import Vue from 'vue'
import App from './App.vue'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import router from '../src/router/index';
import store from '../src/store/index';
import http from './utils/http';

Vue.config.productionTip = false
Vue.prototype.$axios = http;

Vue.use(ElementUI,{ size: 'small', zIndex: 3000 });

// 初始化应用时校验token，并获取用户权限
async function init() {
  const token = await store.dispatch('initToken');
  if(token) {
    const res = await http.get('/getPermission');
    if(res.code !== 1) {
      this.$message.error(res.message);
      return;
    }
    console.log("初始化获取的permission是：",res);
    store.commit('setPermission', {data:res.data});
  }
}

init().then(() => {
  new Vue({
    router,
    store,
    render: h => h(App),
  }).$mount('#app')
});

